/*
 * Created by JFormDesigner on Mon Aug 01 23:13:21 CST 2022
 */

package client.fileMange;

import client.util.ClientConn;
import command.Command;
import command.fileComm.*;
import empty.files.MyFile;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @author unknown
 */
public class FileMange extends JFrame {
    //
    List<String> showPath = new ArrayList<>();
    String path;
    List<Integer> pathId = new ArrayList<>();
    String[] header = {"名称", "上级目录", "类型", "创建时间", "创建者"};
    Object[][] objects = null;


    String father_qx = "00";

    public FileMange() {
        initComponents();
        showPath.add("D:");
        pathId.add(-1);
        showPath();
        tableInit();
    }

    // 显示路径
    public void showPath() {
        String str = "";
        for (String s : showPath) {
            str = str + s + "\\\\";
        }
        this.text_path.setText(str);
        path = str;

        // 切换显示的按钮
        if (showPath.size() != 1) {
            this.btn_create_bxx.setVisible(false);
            this.btn_last.setVisible(true);
            this.btn_create_ml.setVisible(true);
            this.btn_upload.setVisible(true);
        } else {
            this.btn_create_bxx.setVisible(true);
            this.btn_last.setVisible(false);
            this.btn_create_ml.setVisible(false);
            this.btn_upload.setVisible(false);
        }
    }

    // 表格数据初始化
    public void tableInit() {
        Command comm = new CofferSelectCommand();
        try {
            // 发送命令获取数据
            ClientConn.oos.writeObject(comm);
            comm = (Command) ClientConn.ois.readObject();
            List<Object[]> list = (List<Object[]>) comm.getR();
            objects = new Object[list.size()][8];
            int i = 0;
            for (Object[] o : list) {
                objects[i] = o;
                i++;
            }

            // 表格要显示的数据
            Object[][] showObjs = new Object[list.size()][5];
            for (i = 0; i < list.size(); i++) {
                showObjs[i][0] = objects[i][1];
                showObjs[i][1] = "root";
                showObjs[i][2] = objects[i][3];
                showObjs[i][3] = objects[i][4];
                showObjs[i][4] = objects[i][6];
            }
            DefaultTableModel dtf = new DefaultTableModel();
            this.table1.setModel(dtf);
            dtf.setDataVector(showObjs, header);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 表格点击
    private void table1MouseClicked(MouseEvent e) {
        // 右键点击弹出菜单
        if (e.getButton() == MouseEvent.BUTTON3) {
            int focusedRowIndex = this.table1.rowAtPoint(e.getPoint());
            if (focusedRowIndex == -1) {
                return;
            }
            //将表格所选项设为当前右键点击的行
            this.table1.setRowSelectionInterval(focusedRowIndex, focusedRowIndex);
            //弹出菜单
            createPopupMenu(table1, e.getX(), e.getY(), focusedRowIndex);
        }
        // 左键点击
        else {
            TableModel tm = table1.getModel();
            int r = table1.getSelectedRow();

            // 查找权限
            String qx = selectUserqx((int) objects[r][0]);
            String type = (String) objects[r][3];
            // 类型为目录/保险箱 进入
            if (type.equals("保险箱") || type.equals("目录")) {
                // 权限判断
                if (qx.substring(0, 1).equals("1")) {
                    // 添加路径
                    showPath.add((String) objects[r][1]);
                    pathId.add((int) objects[r][0]);
                    showPath();

                    // 发送命令，获取数据
                    Command comm = new FileSelectCommand();
                    comm.setO(objects[r]);
                    try {
                        ClientConn.oos.writeObject(comm);
                        comm = (Command) ClientConn.ois.readObject();
                        List<Object[]> list = (List<Object[]>) comm.getR();
                        objects = new Object[list.size()][8];
                        int i = 0;
                        for (Object[] o : list) {
                            objects[i] = o;
                            i++;
                        }
                        // 表格要显示的数据
                        Object[][] showObjs = new Object[list.size()][5];
                        for (i = 0; i < list.size(); i++) {
                            showObjs[i][0] = objects[i][1];
                            showObjs[i][1] = objects[i][7];
                            showObjs[i][2] = objects[i][3];
                            showObjs[i][3] = objects[i][4];
                            showObjs[i][4] = objects[i][6];
                        }
                        DefaultTableModel dtf = new DefaultTableModel();
                        this.table1.setModel(dtf);
                        dtf.setDataVector(showObjs, header);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }

                    father_qx = qx;
                } else {
                    JOptionPane.showMessageDialog(this, "没有此" + type + "权限");
                }
            }

            // 否则下载文件
            else {
                // 权限判断
                if (qx.substring(0, 1).equals("1")) {
                    int option = JOptionPane.showConfirmDialog(this, (String) objects[r][1], "是否下载此文件", 2);
                    if (option == 0) {
                        try {
                            String name = (String) objects[r][1];
                            Path path1 = choiceDirectory().toAbsolutePath();
                            path1 = Paths.get(path1.toString() + "\\" + name);

                            Command comm = new FileDownloadCommand();
                            MyFile myFile = new MyFile();
                            myFile.setCreate_time(LocalDateTime.now().toString());
                            comm.setPath(path + name);
                            comm.setO(myFile);

                            ClientConn.oos.writeObject(comm);
                            comm = (Command) ClientConn.ois.readObject();

                            if ((Boolean) comm.getR()) {
                                Files.createFile(path1);
                                Files.write(path1, comm.bytes);
                                JOptionPane.showMessageDialog(this, "下载成功");
                            } else {
                                JOptionPane.showMessageDialog(this, "下载失败：" + comm.getE());
                            }
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(this, "下载失败：" + ex);
                        }
                    }
                } else {
                    JOptionPane.showMessageDialog(this, "没有此文件下载权限");
                }
            }
        }
    }

    // 右键菜单
    private void createPopupMenu(JTable jTable, int x, int y, int index) {
        JPopupMenu m_popupMenu = new JPopupMenu();

        // 删除菜单
        JMenuItem delMenItem = new JMenuItem("  删除  ");
        delMenItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                int file_id = (Integer) objects[index][0];
                String qx = selectUserqx(file_id);
                if (qx.substring(1, 2).equals("1")) {
                    String name = (String) objects[index][1];
                    String type = (String) objects[index][3];
                    String create_time = LocalDateTime.now().toString();
                    MyFile myFile = new MyFile();
                    myFile.setId(file_id);
                    myFile.setType(type);
                    myFile.setCreate_time(create_time);

                    Command comm = new DeleteCommand();
                    comm.setO(myFile);
                    comm.setPath(path + name);
                    try {
                        ClientConn.oos.writeObject(comm);
                        comm = (Command) ClientConn.ois.readObject();

                        if ((Boolean) comm.getR()) {
                            JOptionPane.showMessageDialog(null, "删除成功");
                        } else {
                            JOptionPane.showMessageDialog(null, "删除失败：" + comm.getE());
                        }
                    } catch (Exception e) {
                        JOptionPane.showMessageDialog(null, "删除失败");
                    }
                    if (pathId.size() == 1) {
                        tableInit();
                    } else {
                        refrsh();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "没有操作权限");
                }
            }
        });

        // 重命名菜单
        JMenuItem renameMenItem = new JMenuItem("  重命名  ");
        renameMenItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                int id = (Integer) objects[index][0];
                String qx = selectUserqx(id);
                if (qx.substring(1, 2).equals("1")) {
                    String newname = JOptionPane.showInputDialog(null, "", "输入新名称", JOptionPane.DEFAULT_OPTION);
                    newname = newname.trim(); // 去空格
                    if (newname != null && !newname.equals("")) {
                        String oldname = (String) objects[index][1];
                        String type = (String) objects[index][3];
                        String create_time = LocalDateTime.now().toString();
                        MyFile myFile = new MyFile();
                        myFile.setId(id);
                        myFile.setName(newname);
                        myFile.setType(type);
                        myFile.setCreate_time(create_time);

                        Command comm = new RenameCommand();
                        comm.setO(myFile);
                        comm.setPath(path + oldname);
                        try {
                            ClientConn.oos.writeObject(comm);
                            comm = (Command) ClientConn.ois.readObject();

                            if ((Boolean) comm.getR()) {
                                JOptionPane.showMessageDialog(null, "修改成功");
                            } else {
                                JOptionPane.showMessageDialog(null, "修改失败：" + comm.getE());
                            }
                        } catch (Exception e) {
                            JOptionPane.showMessageDialog(null, "修改失败");
                        }
                        // 刷新
                        if (pathId.size() == 1) {
                            tableInit();
                        } else {
                            refrsh();
                        }
                    }
                }
                else {
                    JOptionPane.showMessageDialog(null, "没有操作权限");
                }
            }
        });

        // 添加菜单
        m_popupMenu.add(delMenItem);
        m_popupMenu.add(renameMenItem);
        //弹出菜单
        m_popupMenu.show(jTable, x, y);
    }

    // 返回上一级
    private void btn_last(ActionEvent e) {
        showPath.remove(showPath.size() - 1);
        pathId.remove(pathId.size() - 1);
        showPath();
        if (showPath.size() == 1) {
            tableInit();
        } else {
            // 发送命令，获取数据
            Command comm = new FileSelectCommand();
            comm.setO(new Object[]{(int) pathId.get(pathId.size() - 1)});
            try {
                ClientConn.oos.writeObject(comm);
                comm = (Command) ClientConn.ois.readObject();
                List<Object[]> list = (List<Object[]>) comm.getR();
                objects = new Object[list.size()][8];
                int i = 0;
                for (Object[] o : list) {
                    objects[i] = o;
                    i++;
                }
                // 表格要显示的数据
                Object[][] showObjs = new Object[list.size()][5];
                for (i = 0; i < list.size(); i++) {
                    showObjs[i][0] = objects[i][1];
                    showObjs[i][1] = objects[i][7];
                    showObjs[i][2] = objects[i][3];
                    showObjs[i][3] = objects[i][4];
                    showObjs[i][4] = objects[i][6];
                }
                DefaultTableModel dtf = new DefaultTableModel();
                this.table1.setModel(dtf);
                dtf.setDataVector(showObjs, header);

                father_qx = selectUserqx((int) pathId.get(pathId.size() - 1));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }

    // 新建保险箱
    private void btn_create_bxx(ActionEvent e) {
        while (true) {
            String bxx_name = JOptionPane.showInputDialog(this, "", "输入保险箱名称", JOptionPane.DEFAULT_OPTION);
            bxx_name = bxx_name.trim(); // 去空格
            if (bxx_name != null && !bxx_name.equals("")) {
                // 判断名称是否重复
                if (judgeName(bxx_name, objects)) {
                    JOptionPane.showMessageDialog(this, "名称重复");
                } else {
                    // 保险箱的参数
                    String create_time = String.valueOf(LocalDateTime.now());
                    int create_user = ClientConn.user.getId();
                    MyFile myFile = new MyFile(bxx_name, create_time, create_user);
                    // 发送新建保险箱命令
                    Command comm = new CofferCreateCommand();
                    comm.setO(myFile);
                    // 设置路径
                    comm.setPath(path + bxx_name);
                    try {
                        ClientConn.oos.writeObject(comm);
                        comm = (Command) ClientConn.ois.readObject();
                        if ((Boolean) comm.getR()) {
                            tableInit();
                            JOptionPane.showMessageDialog(this, "创建成功");
                        } else {
                            JOptionPane.showMessageDialog(this, "服务器出错：" + comm.getE());
                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(this, "创建失败");
                    }
                    break;
                }
            } else {
                break;
            }
        }
    }

    // 上传文件
    private void btn_upload(ActionEvent e) {
        if(father_qx.substring(1,2).equals("1")) {
            try {
                // 获取路径
                Path path1 = choiceFile();
                // 读文件
                byte[] bytes = Files.readAllBytes(path1);
                // 文件的参数
                String name = path1.getFileName().toString();
                name = nameDedup(name);
                int father = pathId.get(pathId.size() - 1);
                String type = "文件";
                String create_time = String.valueOf(LocalDateTime.now());
                int create_user = ClientConn.user.getId();
                MyFile myFile = new MyFile(name, father, type, create_time, create_user);
                // 命令
                Command comm = new FileUploadCommand();
                comm.setO(myFile);
                comm.bytes = bytes;
                comm.path = path + name;
                try {
                    ClientConn.oos.writeObject(comm);
                    comm = (Command) ClientConn.ois.readObject();
                    if ((Boolean) comm.getR()) {
                        refrsh();
                        JOptionPane.showMessageDialog(this, "上传成功");
                    } else {
                        JOptionPane.showMessageDialog(this, "服务器出错：" + comm.getE());
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    JOptionPane.showMessageDialog(this, "上传失败");
                }
            } catch (Exception ex) {
                System.out.println("未选择任何文件");
            }
        }
        else {
            JOptionPane.showMessageDialog(this,"没有操作权限");
        }
    }

    // 新建目录
    private void btn_create_ml(ActionEvent e) {
        if(father_qx.substring(1,2).equals("1")) {
            while (true) {
                String ml_name = JOptionPane.showInputDialog(this, "", "输入目录名称", JOptionPane.DEFAULT_OPTION);
                ml_name = ml_name.trim(); // 去空格
                if (ml_name != null && !ml_name.equals("")) {
                    // 判断名称是否重复
                    if (judgeName(ml_name, objects)) {
                        JOptionPane.showMessageDialog(this, "名称重复");
                    } else {
                        // 发送新建目录命令
                        int father = pathId.get(pathId.size() - 1);
                        String type = "目录";
                        int create_user = ClientConn.user.getId();
                        String create_time = String.valueOf(LocalDateTime.now());
                        MyFile myFile = new MyFile(ml_name, father, type, create_time, create_user);
                        Command comm = new DirectoryCreateCommand();
                        comm.setO(myFile);
                        comm.setPath(path + ml_name);
                        try {
                            ClientConn.oos.writeObject(comm);
                            comm = (Command) ClientConn.ois.readObject();
                            if ((Boolean) comm.getR()) {
                                refrsh();
                                JOptionPane.showMessageDialog(this, "创建成功");
                            } else {
                                JOptionPane.showMessageDialog(this, "服务器出错：" + comm.getE());
                            }
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            JOptionPane.showMessageDialog(this, "创建失败");
                        }

                        break;
                    }
                } else {
                    break;
                }
            }
        }
        else {
            JOptionPane.showMessageDialog(this,"没有操作权限");
        }
    }

    // 刷新
    private void refrsh() {
        Command comm = new FileSelectCommand();
        comm.setO(new Object[]{pathId.get(pathId.size() - 1)});
        try {
            ClientConn.oos.writeObject(comm);
            comm = (Command) ClientConn.ois.readObject();
            List<Object[]> list = (List<Object[]>) comm.getR();
            objects = new Object[list.size()][8];
            int i = 0;
            for (Object[] o : list) {
                objects[i] = o;
                i++;
            }
            // 表格要显示的数据
            Object[][] showObjs = new Object[list.size()][5];
            for (i = 0; i < list.size(); i++) {
                showObjs[i][0] = objects[i][1];
                showObjs[i][1] = objects[i][7];
                showObjs[i][2] = objects[i][3];
                showObjs[i][3] = objects[i][4];
                showObjs[i][4] = objects[i][6];
            }
            DefaultTableModel dtf = new DefaultTableModel();
            this.table1.setModel(dtf);
            dtf.setDataVector(showObjs, header);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    // 判断名称是否重复
    public boolean judgeName(String name, Object[][] objects) {
        for (Object[] os : objects) {
            if (name.equals((String) os[1])) {
                return true;
            }
        }
        return false;
    }

    // 文件名称去重
    public String nameDedup(String name) {
        // 分割文件名和后缀名
        int n = name.lastIndexOf(".");
        String str1 = name.substring(0, n);
        String str2 = name.substring(n);

        // 去重
        int i = 1;
        String newname = name;
        while (judgeName(newname, objects)) {
            newname = str1 + "(" + String.valueOf(i) + ")" + str2;
            i++;
        }

        return newname;
    }

    // 文件选择界面，用于文件上传
    public Path choiceFile() throws Exception {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.showDialog(this, "选择文件");
        File file = chooser.getSelectedFile();
        return file.toPath();
    }

    // 目录选择界面，用于文件下载
    public Path choiceDirectory() throws Exception {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.showDialog(this, "选择文件保存位置");
        File file = chooser.getSelectedFile();
        return file.toPath();
    }

    // 权限查找
    public String selectUserqx(int file_id) {
        Command qx_comm = new SelectQxCommand();
        qx_comm.setO(file_id);
        qx_comm.user = ClientConn.user;
        String qx = "00";
        try {
            ClientConn.oos.writeObject(qx_comm);
            qx_comm = (Command) ClientConn.ois.readObject();
            if (qx_comm.getR() != null) {
                qx = String.valueOf(qx_comm.getR());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return qx;
    }


    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        panel1 = new JPanel();
        text_path = new JTextField();
        scrollPane1 = new JScrollPane();
        table1 = new JTable();
        btn_last = new JButton();
        btn_upload = new JButton();
        btn_create_ml = new JButton();
        btn_create_bxx = new JButton();

        //======== this ========
        setResizable(false);
        setTitle("\u6587\u4ef6\u7ba1\u7406");
        var contentPane = getContentPane();

        //======== panel1 ========
        {
            panel1.setBackground(Color.white);

            //---- text_path ----
            text_path.setEditable(false);
            text_path.setEnabled(false);
            text_path.setBackground(Color.white);
            text_path.setDisabledTextColor(Color.black);
            text_path.setFont(new Font("\u5fae\u8f6f\u96c5\u9ed1", Font.PLAIN, 16));
            text_path.setVisible(false);

            //======== scrollPane1 ========
            {

                //---- table1 ----
                table1.setGridColor(Color.black);
                table1.setCellSelectionEnabled(true);
                table1.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {
                        table1MouseClicked(e);
                    }
                });
                scrollPane1.setViewportView(table1);
            }

            //---- btn_last ----
            btn_last.setText("\u8fd4\u56de\u4e0a\u4e00\u7ea7");
            btn_last.setVisible(false);
            btn_last.addActionListener(e -> btn_last(e));

            //---- btn_upload ----
            btn_upload.setText("\u4e0a\u4f20\u6587\u4ef6");
            btn_upload.setVisible(false);
            btn_upload.addActionListener(e -> btn_upload(e));

            //---- btn_create_ml ----
            btn_create_ml.setText("\u65b0\u5efa\u76ee\u5f55");
            btn_create_ml.setVisible(false);
            btn_create_ml.addActionListener(e -> btn_create_ml(e));

            //---- btn_create_bxx ----
            btn_create_bxx.setText("\u65b0\u5efa\u4fdd\u9669\u7bb1");
            btn_create_bxx.addActionListener(e -> btn_create_bxx(e));

            GroupLayout panel1Layout = new GroupLayout(panel1);
            panel1.setLayout(panel1Layout);
            panel1Layout.setHorizontalGroup(
                    panel1Layout.createParallelGroup()
                            .addGroup(panel1Layout.createSequentialGroup()
                                    .addContainerGap()
                                    .addGroup(panel1Layout.createParallelGroup()
                                            .addGroup(panel1Layout.createSequentialGroup()
                                                    .addComponent(btn_last, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                                    .addComponent(btn_create_ml, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(btn_create_bxx, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE)
                                                    .addGap(45, 45, 45)
                                                    .addComponent(btn_upload, GroupLayout.PREFERRED_SIZE, 103, GroupLayout.PREFERRED_SIZE))
                                            .addComponent(text_path, GroupLayout.Alignment.TRAILING)
                                            .addComponent(scrollPane1, GroupLayout.DEFAULT_SIZE, 953, Short.MAX_VALUE))
                                    .addContainerGap())
            );
            panel1Layout.setVerticalGroup(
                    panel1Layout.createParallelGroup()
                            .addGroup(panel1Layout.createSequentialGroup()
                                    .addComponent(text_path, GroupLayout.PREFERRED_SIZE, 42, GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                            .addComponent(btn_last, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
                                            .addComponent(btn_upload, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
                                            .addComponent(btn_create_ml, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE)
                                            .addComponent(btn_create_bxx, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE))
                                    .addGap(18, 18, 18)
                                    .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 421, GroupLayout.PREFERRED_SIZE)
                                    .addContainerGap(14, Short.MAX_VALUE))
            );
        }

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
                contentPaneLayout.createParallelGroup()
                        .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        contentPaneLayout.setVerticalGroup(
                contentPaneLayout.createParallelGroup()
                        .addComponent(panel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JPanel panel1;
    private JTextField text_path;
    private JScrollPane scrollPane1;
    private JTable table1;
    private JButton btn_last;
    private JButton btn_upload;
    private JButton btn_create_ml;
    private JButton btn_create_bxx;
    // JFormDesigner - End of variables declaration  //GEN-END:variables

    public static void main(String[] args) throws Exception {
        FileMange fm = new FileMange();
        fm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        fm.setVisible(true);
        //String lookAndFeel = "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel";
        //UIManager.setLookAndFeel(lookAndFeel);
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
}